<?php
class Search_View_Helper_ColorFind extends Zend_View_Helper_Abstract {
	public function colorFind($findText, $content = null) {
		if ($content == null) {
			$content = $findText;
		} else {
			$this->setFindText($findText);
		}
		
		$findText = $this->getFindText();
		$findTextReplace = $this->getFindTextReplace($findText);

		if (strlen($content) < 200) {
			return str_ireplace($findText, $findTextReplace, $content);
		} else {
			return str_ireplace($findText, $findTextReplace, $content);
		}
	}

	/**
	 * @var unknown_type
	 */
	protected $_findText;
	
	/**
	 * @param string $text
	 * @return Search_View_Helper_ColorFind
	 */
	public function setFindText($text) {
		$this->_findText = (string) $text;
		return $this;
	}

	/**
	 * @return array
	 */
	public function getFindText() {
		return (array) explode(' ', $this->_findText);
	}
	
	/**
	 * @param array $find
	 * @return array
	 */
	public function getFindTextReplace(array $find) {
		$replace = array();
		
		foreach ($find as $value) {
			$replace[] = sprintf('<b>%s</b>', $value);
		}

		return $replace;
	}
}